// 标定用来计算批量任务结束时间
let secsList
// 当前标定快速
var fast
// 当前标定慢速
var slow

var pondStatus = 0;

var hourJson = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23"]

var minJson = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23",
    "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49",
    "50", "51", "52", "53", "54", "55", "56", "57", "58", "59"]

var end = new Date(new Date().toLocaleDateString());

var stationId = $.trim(MX.getQueryVariable("id"));
if (stationId == null || stationId === "null" || !stationId) {
    LayerUtil.failMsg("未找到设备详情，请重新进入")
}

var workshopSelect = [];
var specieSelect = [];
var calibrationSelect = [];
var stationTypeSelect = [];

function checkZiliaoForm(validatorDom) {
    if (validatorDom.attr("name") === "name" && validatorDom.val().length > 100) {
        return {
            "retBool": true,
            "msg": "设备名称长度不能超过100个字符"
        };
    }
}

function checkShengChanForm(validatorDom) {
    if (validatorDom.attr("name") === "speciesSpec" && validatorDom.val() < 0) {
        return {
            "retBool": true,
            "msg": "物种规格不能小于0"
        };
    }
    if (validatorDom.attr("name") === "speciesNum" && validatorDom.val() < 0) {
        return {
            "retBool": true,
            "msg": "物种数量不能小于0"
        };
    }
    if (validatorDom.attr("name") === "sales" && validatorDom.val() < 0) {
        return {
            "retBool": true,
            "msg": "销售数量不能小于0"
        };
    }
    if (validatorDom.attr("name") === "death" && validatorDom.val() < 0) {
        return {
            "retBool": true,
            "msg": "死亡数量不能小于0"
        };
    }
    if (validatorDom.attr("name") === "poolLong" && validatorDom.val() < 0) {
        return {
            "retBool": true,
            "msg": "养殖池长度(半径)不能小于0"
        };
    }
    if (validatorDom.attr("name") === "poolWidth" && validatorDom.val() < 0) {
        return {
            "retBool": true,
            "msg": "养殖池宽度不能小于0"
        };
    }
    if (validatorDom.attr("name") === "poolHeight" && validatorDom.val() < 0) {
        return {
            "retBool": true,
            "msg": "养殖池高度不能小于0"
        };
    }
    if (validatorDom.attr("name") === "poolVolume" && validatorDom.val() < 0) {
        return {
            "retBool": true,
            "msg": "养殖池体积不能小于0"
        };
    }
}

function checkTaskForm(validatorDom) {
    var h = validatorDom.parent().parent().find("td:eq(1)").children().val()
    var min = validatorDom.parent().parent().find("td:eq(2)").children().val()
    var mode = validatorDom.parent().parent().find("td:eq(3)").children().val()
    var maxWeight
    if (mode == 'high') {
        maxWeight = Math.ceil(100 / fast * 32700)
    } else {
        maxWeight = Math.ceil(100 / slow * 32700)
    }
    var secs100 = mode == "normal" ? slow : fast;
    var secs = secs100 * validatorDom.val() / 100 / 60;
    var weight = Math.ceil((1380 - (Number(h * 60) + Number(min))) * 60 * 100 / secs100) - 1
    if (weight > maxWeight) {
        weight = maxWeight
    }
    if (Number(h * 60) + Number(min) + secs < 60 || Number(h * 60) + Number(min) + secs > 1380 || Number(h * 60) < 60) {
        if (Number(h) != 0 && Number(h) != 23) {
            if (weight == maxWeight) {
                return {
                    "retBool": true,
                    "msg": "超出最大投喂时间" + "(" + "推荐投喂：" + weight + "g)"
                };
            } else {
                return {
                    "retBool": true,
                    "msg": "投喂结束时间处于系统维护期间" + "(" + "推荐投喂：" + weight + "g)"
                };
            }
        } else {
            return {
                "retBool": true,
                "msg": "投喂时间处于系统维护期间"
            };
        }
    }
    if (validatorDom.val() > maxWeight) {
        return {
            "retBool": true,
            "msg": "超出最大投喂时间" + "(" + "推荐投喂：" + weight + "g)"
        };
    }
    if (validatorDom.attr("name") === "weight" && validatorDom.val() < 0.00001) {
        return {
            "retBool": true,
            "msg": "投喂量必须大于0"
        };
    }
}

function checkReplenishForm(validatorDom) {
    var freesecs = $("#freesecs").val();//获取秒数
    var h = new Date().getHours()
    var min = new Date().getMinutes()
    var s = new Date().getSeconds()
    var difference = 82800 - (h * 60 * 60 + min * 60 + s)
    if (h == 0 || h == 23) {
        return {
            "retBool": true,
            "msg": "当前处于系统维护期间"
        };
    }
    if (freesecs <= 0) {
        return {
            "retBool": true,
            "msg": "指定时长必须大于0"
        };
    }
    if (freesecs > difference && difference < 32700) {
        return {
            "retBool": true,
            "msg": "投喂结束处于系统维护期间（推荐时长：" + difference + ")"
        };
    }
    if (freesecs > 32700) {
        return {
            "retBool": true,
            "msg": "指定时长最大值为32700"
        };
    }
}

$(function () {
    //初始化表格
    Table.builder()
        .dom($(".feedDay"))
        .searchButton($(".feedDaySearchButton"))
        .resetButton($(".feedDayRestButton"))
        .searchDom($(".feedDaySearchForm"))
        .listUrl(STAION_FEED_RECORD_DAY_LIST + "?stationId=" + stationId)
        .columns(feedDay)
        .init()
    Table.builder()
        .dom($(".monthProducts"))
        .searchButton($("#searchButton"))
        .resetButton($("#resetButton"))
        .searchDom($("#searchForm"))
        .listUrl(STAION_PRODUCE_RECORD_LIST + "?stationId=" + stationId)
        .columns(monthProducts)
        .init()
    Table.builder()
        .dom($(".contr"))
        .searchButton($(".contrSearchButton"))
        .resetButton($(".contrRestButton"))
        .searchDom($(".contrSearchForm"))
        .listUrl(STAION_CONTROL_RECORD_LIST + "?stationId=" + stationId)
        .columns(contr)
        .init()

    //初始化下拉选
    $("#task_form").find(".select-init").each(function () {
        var that = $(this);
        var html = "";
        html += "<option value=''>请选择</option>"
        Request.builder()
            .url(STATION_ALL_SELECT)
            .isToken(true)
            .callback(function (e) {
                if (e.code === "00000") {
                    workshopSelect = e.workshops;
                    specieSelect = e.species;
                    calibrationSelect = e.calibrations;
                    stationTypeSelect = e.stationTypes;
                    Select.builder()
                        .dom($("#workshopId"))
                        .data(workshopSelect)
                        .initByData();
                    Select.builder()
                        .dom($("#speciesId"))
                        .data(specieSelect)
                        .initByData();
                    Select.builder()
                        .dom($("#speciesIdTwo"))
                        .data(specieSelect)
                        .initByData();
                    Select.builder()
                        .dom($("#typeId"))
                        .data(stationTypeSelect)
                        .initByData();
                    secsList = calibrationSelect
                    $.each(calibrationSelect, function (index, item) {
                        html += "<option value='" + item["id"] + "' nsecs='" + item["normalSecs"] + "' hsecs='" + item["highSecs"] + "' id='" + ('calibrationId' + index) + "'>";
                        if (item.showType === 0) {
                            html += "" + item["name"] + "mm" + "—(" + "";
                            if (item.normalValue !== "") {
                                html += item.normalValue + ";";
                            }
                            if (item.highValue !== "") {
                                html += item.highValue + ";";
                            }
                            html += ")" + "</option>";
                        } else {
                            if (item.shortName === "") {
                                html += "" + item["name"] + "mm" + "";
                            } else {
                                html += "" + item["shortName"] + "";
                            }
                        }
                    });
                    that.html(html);
                }
            }).get();
    })

    //设置页面详情内容
    $("#feedTime").html(DateUtil.changeDateToString(new Date().getTime(), DateFormatEnum.YYYY_MM_DD));
    detail();

    $("input[name='speciesSpec']").TouchSpin({
        "step": 0.1,
        "max": null,
        "decimals": 1
    });

    //跳转通讯
    $(".toCmd").click(function () {
        window.open("/admin/station/cmd.html?id=" + stationId);
    });

    //跳转通讯
    $(".toCmdCancel").click(function () {
        window.open("/admin/station/cmd_cancel.html?id=" + stationId);
    });

    $(".btn_dif_function").on("click", function () {
        var dom = $(this).attr("data-target");
        //删除input下方的红字提醒
        if ($(dom).find(".has-error").length > 0) {
            $(dom).find(".has-error").each(function () {
                $(this).removeClass("has-error")
            })
        }
        if ($(dom).find(".help-block").length > 0) {
            $(dom).find(".help-block").each(function () {
                $(this).remove()
            })
        }
    })
    //30日投喂趋势
    touwei("");
    //30日投喂趋势查询
    $("#30TimeSearch").click(function () {
        var time = $.trim($("#30Time").val());
        touwei(time);
    })
    //30日投喂趋势重置查询
    $("#30TimeReset").click(function () {
        $("#30Time").val("");
        touwei("");
    })

    document.getElementById("30Time").value = DateUtil.changeDateToString(new Date().getTime(), DateFormatEnum.YYYY_MM);
    //点击更新资料
    $("#openZiliao").click(function () {
        Request.builder()
            .url(STATION_INFO_DETAIL + "/" + stationId)
            .isToken(true)
            .callback(function (e) {
                Form.setValues($("#commonForm"), e.data)
            }).get();
    })

    //点击计算体积1
    $("#btn_squaresPond").click(function () {
        var long = document.getElementById("poolLong").value;
        var width = document.getElementById("poolWidth").value;
        var height = document.getElementById("poolHeight").value;
        var volume = document.getElementById("poolVolume");

        volume.value = long * width * height;
    })
    //点击计算体积2
    $("#btn_circlesPond").click(function () {
        var radius = document.getElementById("poolLong2").value;
        var width = 0;
        var high = document.getElementById("poolHeight2").value;
        var volume2 = document.getElementById("poolVolume2");

        volume2.value = (Math.PI * radius * radius * high).toFixed(1);
    })
    //点击计算体积3
    $("#btn_anisePond").click(function () {
        var long = document.getElementById("poolLong3").value;
        var width = document.getElementById("poolWidth3").value;
        var height = document.getElementById("poolHeight3").value;
        var volume = document.getElementById("poolVolume3");

        volume.value = long * 8 * width * height;
    })
    //完善资料
    $("#infoSubmit").click(function () {
        var data = Form.getValues($("#commonForm"))
        Validator.builder()
            .dom($("#commonForm"))
            .customValidate(checkZiliaoForm)
            .customSubmit(function (e) {
                if (!e) {
                    return false;
                }
                Request.builder()
                    .url(STATION_UPDATE_INFO)
                    .data(data)
                    .isToken(true)
                    .callback(function (e) {
                        if (e.code === "00000") {
                            LayerUtil.successMsg(ERROR_MSG.SUCCESS)
                            setTimeout(function () {
                                $("#commonDiv").find(".close").trigger("click");
                                detail();
                            }, 1000)
                        } else {
                            LayerUtil.failMsg(e.msg != null ? e.msg : ERROR_MSG.FAIL)
                        }
                        $(".mx_validator_button").attr("disabled", false)
                    }).post();
            }, null).do();
    })

    //点击更新生产
    $("#openShengchan").click(function () {
        Request.builder()
            .url(STAION_PRODUCE_RECORD_DETAIL + "?stationId=" + stationId)
            .isToken(true)
            .callback(function (e) {
                if (e.data.pond == 0) {
                    squaresPondShow.style.display = "block";
                    circlesPondShow.style.display = "none";
                    anisePondShow.style.display = "none";
                    var radio = document.getElementsByName("pond");
                    radio[0].checked = true;
                    pondStatus = 0;
                    document.getElementById("poolLong").value = e.data.poolLong;
                    document.getElementById("poolWidth").value = e.data.poolWidth;
                    document.getElementById("poolHeight").value = e.data.poolHeight;
                    document.getElementById("poolVolume").value = e.data.poolVolume;
                } else if (e.data.pond == 1) {
                    squaresPondShow.style.display = "none";
                    circlesPondShow.style.display = "block";
                    anisePondShow.style.display = "none";
                    var radio = document.getElementsByName("pond");
                    radio[1].checked = true;
                    pondStatus = 1;
                    document.getElementById("poolLong2").value = e.data.poolLong;
                    document.getElementById("poolHeight2").value = e.data.poolHeight;
                    document.getElementById("poolVolume2").value = e.data.poolVolume;
                } else if (e.data.pond == 2) {
                    squaresPondShow.style.display = "none";
                    circlesPondShow.style.display = "none";
                    anisePondShow.style.display = "block";
                    var radio = document.getElementsByName("pond");
                    radio[2].checked = true;
                    pondStatus = 2;
                    document.getElementById("poolLong3").value = e.data.poolLong;
                    document.getElementById("poolWidth3").value = e.data.poolWidth;
                    document.getElementById("poolHeight3").value = e.data.poolHeight;
                    document.getElementById("poolVolume3").value = e.data.poolVolume;
                }
                Form.setValues($("#species_form"), e.data)
                $("#worklog_date").html(e.data.time);
            }).get();
    })
    //更新生产
    $("#updateShengchan").click(function () {
        var data = Form.getValues($("#species_form"))
        if (pondStatus == 0) {
            data.pond = pondStatus
            data.poolLong = document.getElementById("poolLong").value;
            data.poolWidth = document.getElementById("poolWidth").value;
            data.poolHeight = document.getElementById("poolHeight").value;
            data.poolVolume = document.getElementById("poolVolume").value;
        } else if (pondStatus == 1) {
            data.pond = pondStatus
            data.poolLong = document.getElementById("poolLong2").value;
            data.poolWidth = 0;
            data.poolHeight = document.getElementById("poolHeight2").value;
            data.poolVolume = document.getElementById("poolVolume2").value;
        } else if (pondStatus == 2) {
            data.pond = pondStatus
            data.poolLong = document.getElementById("poolLong3").value;
            data.poolWidth = document.getElementById("poolWidth3").value;
            data.poolHeight = document.getElementById("poolHeight3").value;
            data.poolVolume = document.getElementById("poolVolume3").value;
        }
        Validator.builder()
            .dom($("#species_form"))
            .customValidate(checkShengChanForm)
            .customSubmit(function (e) {
                if (!e) {
                    return false;
                }
                Request.builder()
                    .url(STAION_PRODUCE_RECORD_UPDATE)
                    .data(data)
                    .isToken(true)
                    .callback(function (e) {
                        if (e.code === "00000") {
                            LayerUtil.successMsg(ERROR_MSG.SUCCESS)
                            setTimeout(function () {
                                $("#updateDIV").find(".close").trigger("click");
                                detail();
                            }, 1000)
                        } else {
                            LayerUtil.failMsg(e.msg != null ? e.msg : ERROR_MSG.FAIL)
                        }
                        $(".mx_validator_button").attr("disabled", false)
                    }).post();
            }, null).do()
    })

    //温度的切换
    $("#airTemp").click(function () {
        if ($("#airTemp").hasClass("tempChoose")) {
            $("#airTemp").toggleClass("");
        } else {
            $("#airTemp").toggleClass("tempChoose");
        }
        $("#waterTemp").removeClass("tempChoose");
        updateTempType(1);
        $("#yincang").hide()
        $("#yincang1").show()
    })
    $("#waterTemp").click(function () {
        $("#airTemp").removeClass("tempChoose");
        if ($("#waterTemp").hasClass("tempChoose")) {
            $("#waterTemp").toggleClass("");
        } else {
            $("#waterTemp").toggleClass("tempChoose");
        }
        updateTempType(0);
        $("#yincang").show()
        $("#yincang1").hide()
    })

    var version = 0;
    $("#tooSetTask").click(function () {
        Request.builder()
            .url(STATION_DETAIL + "/" + stationId)
            .isToken(true)
            .callback(function (e) {
                if (e.code === "00000") {
                    if (e.data.type) {
                        var lock = false;
                        var confirm = LayerUtil.confirm("当前设备为校准设备，是否切换为常规机器?", function () {
                            if (!lock) {
                                lock = true;
                                Request.builder()
                                    .url(STATION_SET_JZ + "/" + stationId + "/" + 0)
                                    .isToken(true)
                                    .callback(function (e) {
                                        if (e.code === "00000") {
                                            LayerUtil.successMsg(ERROR_MSG.SUCCESS)
                                            setTimeout(function () {
                                                $("#toSetTask").click()
                                            }, 1000)
                                        } else {
                                            LayerUtil.failMsg(e.msg != null ? e.msg : ERROR_MSG.FAIL)
                                        }
                                    }).post();
                                layer.close(confirm);
                            }
                        }, null)
                    } else {
                        $("#toSetTask").click()
                    }
                }
            }).get();
    })

    //点击设置任务
    $("#toSetTask").click(function () {
        Request.builder()
            .url(STATION_TASK_DETAIL + "/" + stationId)
            .isToken(true)
            .callback(function (e) {
                var d = e.data;
                version = e.version;
                var html = "";
                $("#task_form").find("select").val(d.calibrationId);
                Form.setValues($("#task_form"), d)
                if (d.taskJson != null && d.taskJson !== "") {
                    var taskJson = JSON.parse(d.taskJson);
                    var orderArr = sortObjectArray(taskJson, ['hour', 'min'], "asc");
                    $.each(orderArr, function (index, item) {
                        var hour = item.hour;
                        var min = item.min;
                        var week = item.week;//1,2,3,4,5
                        var htmlWeek = ``
                        if (week !== null && week !== undefined) {
                            var arr = week.toString().split(",");
                            if (arr.length !== 7) {
                                if (arr.indexOf('1') != -1) {
                                    htmlWeek += `周一`
                                }
                                if (arr.indexOf('2') != -1) {
                                    htmlWeek += `周二`
                                }
                                if (arr.indexOf('3') != -1) {
                                    htmlWeek += `周三`
                                }
                                if (arr.indexOf('4') != -1) {
                                    htmlWeek += `周四`
                                }
                                if (arr.indexOf('5') != -1) {
                                    htmlWeek += `周五`
                                }
                                if (arr.indexOf('6') != -1) {
                                    htmlWeek += `周六`
                                }
                                if (arr.indexOf('7') != -1) {
                                    htmlWeek += `周日`
                                }
                                htmlWeek = htmlWeek.replace(/(.{2})/g, "$1，"); // 在每两个字符后面添加逗号
                                //去最后的点
                                htmlWeek = htmlWeek.substring(0, htmlWeek.length - 1);
                            } else {
                                htmlWeek += "每天";
                            }
                        } else {
                            htmlWeek += "每天";
                        }
                        // 设置周
                        if (version === 1 || version === 2) {
                            html += '<tr>' +
                                '<td style="position: relative;text-align: center">';
                            html += `<div class="popupDiv" dataType="${htmlWeek}">
                                  ${htmlWeek}
                              </div>
                            <div class="popupShowDiv" style="visibility: hidden;display: none;">${htmlWeek}</div>`
                            html += '</td>';
                        } else if (version === 3) {
                            html += '<tr>' +
                                '<td style="position: relative;text-align: center">';
                            html += `<div class="popupDiv"  onmouseover="showPopupShowDiv()" onmouseout="clearPopupShowDiv()" type="button" dataType="${htmlWeek}" data-toggle="modal" data-target="#weekChooseDiv">
                                  ${htmlWeek}
                              </div>
                            <div class="popupShowDiv" style="visibility: hidden;display: none;">${htmlWeek}</div>`
                            html += '</td>';
                        }
                        //设置小时
                        html += '<td><select class="form-control input-sm">';
                        $.each(hourJson, function (indexHour, itemHour) {
                            if (itemHour === hour) {
                                html += '<option value="' + itemHour + '" selected>' + itemHour + '时</option>';
                            } else {
                                html += '<option value="' + itemHour + '">' + itemHour + '时</option>';
                            }
                        });
                        html += '</select></td>';
                        //设置分钟
                        html += '<td><select class="form-control input-sm">';
                        $.each(minJson, function (indexMin, itemMin) {
                            if (itemMin === min) {
                                html += '<option value="' + itemMin + '" selected>' + itemMin + '分</option>';
                            } else {
                                html += '<option value="' + itemMin + '">' + itemMin + '分</option>';
                            }
                        });
                        html += '</select></td>';

                        html += '<td>' +
                            '<select class="form-control input-sm" id="speed">';
                        if (item.mode === 'high') {
                            html += '<option value="normal" >低速模式</option>' +
                                '<option value="high" selected>高速模式</option>';
                        } else {
                            html += '<option value="normal" selected>低速模式</option>' +
                                '<option value="high" >高速模式</option>';
                        }
                        html += '</select>' +
                            '</td>' +
                            '<td class="mx_validator">' +
                            '<input type="text" value="' + item.weight + '" name="weight" class="form-control touchSpin mx_required mx_custom" mx_required_msg="投喂量不能为空">' +
                            '</td>' +
                            '<td><button class="btn btn-danger btn-del-task btn-sm"">删除</button></td>' +
                            '</tr>';
                    });
                }
                $("#tasks").html(html);
            }).get();
    })

    $('#weekSave').click(function () {
        //获取checkBox的元素
        var ids = $('input[type=checkbox]');
        var data = '';
        ids.each(function () {
            //获取当前元素的勾选状态
            if ($(this).prop("checked")) {
                data = data + $(this)[0].labels[0].innerHTML + "，";
            }
        });
        if (!data) {
            return LayerUtil.failMsg("选择星期不能为空");
        }
        //去最后的点
        data = data.substring(0, data.length - 1);
        if (data.length === 20) {
            data = "每天";
        }
        var html = `<div class="popupDiv"  onmouseover="showPopupShowDiv()" onmouseout="clearPopupShowDiv()" type="button" dataType="${data}" data-toggle="modal" data-target="#weekChooseDiv">
                          ${data}
                      </div>
                    <div class="popupShowDiv" style="visibility: hidden;display: none;">${data}</div>`;
        $("#updateHtmlID").html(html);
        document.getElementById("updateHtmlID").removeAttribute("id");
        $("#weekChooseDiv").find(".close").trigger("click");
    })

    $("#tasks").on("click", ".popupDiv", function () {
        var dom = $(this).attr("dataType");
        var arr = dom.toString().split("，");
        $(this).parent().attr("id", "updateHtmlID");
        var html = ``
        if (arr.indexOf('每天') != -1) {
            html += monday + tuesday + wednesday + thursday + friday + saturday + sunday;
        } else {
            if (arr.indexOf('周一') != -1) {
                html += monday
            } else {
                html += noMonday
            }
            if (arr.indexOf('周二') != -1) {
                html += tuesday
            } else {
                html += noTuesday
            }
            if (arr.indexOf('周三') != -1) {
                html += wednesday
            } else {
                html += noWednesday
            }
            if (arr.indexOf('周四') != -1) {
                html += thursday
            } else {
                html += noThursday
            }
            if (arr.indexOf('周五') != -1) {
                html += friday
            } else {
                html += noFriday
            }
            if (arr.indexOf('周六') != -1) {
                html += saturday
            } else {
                html += noSaturday
            }
            if (arr.indexOf('周日') != -1) {
                html += sunday
            } else {
                html += noSunday
            }
        }
        $('#weekChooseList').html(html)
    })

    //添加一行
    $("#btn-add-task").click(function () {
        var html = html += '<tr>';
        //设置周
        if (version === 1 || version === 2) {
            html += '<td style="position: relative;text-align: center">';
            html += `<div class="popupDiv" dataType="每天" >
                                  每天
                              </div>
                            <div class="popupShowDiv" style="visibility: hidden;display: none;">每天</div>`
            html += '</td>';
        } else if (version === 3) {
            html += '<td style="position: relative;text-align: center">';
            html += `<div class="popupDiv"  onmouseover="showPopupShowDiv()" onmouseout="clearPopupShowDiv()" type="button" dataType="每天" data-toggle="modal" data-target="#weekChooseDiv">
                                  每天
                              </div>
                            <div class="popupShowDiv" style="visibility: hidden;display: none;">每天</div>`
            html += '</td>';
        }
        //设置小时
        html += '<td><select class="form-control input-sm">';
        $.each(hourJson, function (indexHour, itemHour) {
            if ("00" === itemHour) {
                html += '<option value="' + itemHour + '" selected>' + itemHour + '时</option>';
            } else {
                html += '<option value="' + itemHour + '">' + itemHour + '时</option>';
            }
        });
        html += '</select></td>';
        //设置分钟
        html += '<td><select class="form-control input-sm">';
        $.each(minJson, function (indexMin, itemMin) {
            if ("00" === itemMin) {
                html += '<option value="' + itemMin + '" selected>' + itemMin + '分</option>';
            } else {
                html += '<option value="' + itemMin + '">' + itemMin + '分</option>';
            }
        });
        html += '</select></td>';

        html += '<td>' +
            '<select class="form-control input-sm" id="speed">' +
            '<option value="normal" selected>低速模式</option>' +
            '<option value="high" >高速模式</option>' +
            '</select>' +
            '</td>' +
            '<td class="mx_validator">' +
            '<input type="text" placeholder="请输入投喂量" name="weight" class="form-control touchSpin mx_required mx_custom" mx_required_msg="投喂量不能为空">' +
            '</td>' +
            '<td><button class="btn btn-danger btn-del-task btn-sm"">删除</button></td>' +
            '</tr>';

        $("#tasks").append(html);
    })

    //删除一行
    $("#tasks").on("click", ".btn-del-task", function () {
        $(this).parent().parent().remove();
    })

    //保存任务
    $("#btn_upd_task").click(function () {
        var data = Form.getValues($("#task_form"))
        data.id = stationId;
        secsList.map(item => {
            if (item.id === data.calibrationId) {
                fast = item.highSecs / 100
                slow = item.normalSecs / 100
            }
        })
        Validator.builder()
            .dom($("#task_form"))
            .customValidate(checkTaskForm)
            .customSubmit(function (e) {
                if (!e) {
                    return false;
                }
                var tasks = [];
                var hmmap = {};
                var timeDate = [];
                var flag = 0;
                $("#tasks tr").each(function () {
                    var weeks = $(this).find(".popupDiv");
                    var cols = $(this).find("select");
                    var vals = $(this).find("input");
                    var task = {};

                    var week = $(weeks[0]).html().trim();
                    var returnWeek = "";
                    if (week !== null) {
                        var arr = week.toString().split("，");
                        if (arr.length !== 7) {
                            if (arr.indexOf('每天') != -1) {
                                returnWeek += `1234567`
                            }
                            if (arr.indexOf('周一') != -1) {
                                returnWeek += `1`
                            }
                            if (arr.indexOf('周二') != -1) {
                                returnWeek += `2`
                            }
                            if (arr.indexOf('周三') != -1) {
                                returnWeek += `3`
                            }
                            if (arr.indexOf('周四') != -1) {
                                returnWeek += `4`
                            }
                            if (arr.indexOf('周五') != -1) {
                                returnWeek += `5`
                            }
                            if (arr.indexOf('周六') != -1) {
                                returnWeek += `6`
                            }
                            if (arr.indexOf('周日') != -1) {
                                returnWeek += `7`
                            }
                            returnWeek = returnWeek.replace(/(.{1})/g, "$1,"); // 在每两个字符后面添加逗号
                            //去最后的点
                            returnWeek = returnWeek.substring(0, returnWeek.length - 1);
                        }
                    } else {
                        returnWeek += "1,2,3,4,5,6,7";
                    }
                    var hour = $(cols[0]).val().trim();
                    var min = $(cols[1]).val().trim();
                    var speedMode = $(cols[2]).val().trim();
                    var weight = $(vals[0]).val().trim();
                    if (!hour || !min || !speedMode || !weight) {
                        LayerUtil.failMsg("所有项目都必填");
                        flag = 1;
                        return false;
                    }
                    task['week'] = returnWeek;
                    task['hour'] = hour;
                    task['min'] = min;
                    task['mode'] = speedMode;
                    task['weight'] = Number(weight);
                    var weekArr = returnWeek.toString().split(",");
                    $.each(weekArr, function (index, item) {
                        var timeKey = item + '_' + task['hour'] + '_' + task['min'];
                        if (!timeDate.includes(timeKey)) {
                            timeDate.push(timeKey);
                        } else {
                            LayerUtil.failMsg("时间段重复了,请检查");
                            flag = 1;
                            return false;
                        }
                    })
                    var key = task['week'] + '_' + task['hour'] + '_' + task['min'];
                    if (!hmmap[key]) {
                        hmmap[key] = true;
                        tasks.push(task);
                    }
                    if (tasks.length > 24) {
                        LayerUtil.failMsg("任务数量不能大于24个");
                        flag = 1;
                        return false;
                    }
                })
                var orderArr = sortObjectArray(tasks, ['hour', 'min'], "asc");
                setTimeout(() => {
                    data.tasks = JSON.stringify(orderArr);
                    if (flag === 0) {
                        Request.builder()
                            .url(STATION_TASK_UPDATE + "/" + stationId)
                            .data(data)
                            .isToken(true)
                            .callback(function (e) {
                                if (e.code === "00000") {
                                    LayerUtil.successMsg(ERROR_MSG.SUCCESS)
                                    setTimeout(function () {
                                        $("#settaskDIV").find(".close").trigger("click");
                                        detail();
                                    }, 1000)
                                } else {
                                    LayerUtil.failMsg(e.msg != null ? e.msg : ERROR_MSG.FAIL)
                                }
                            }).post();
                    }
                }, 10)
            }, null).do();
    })

    //调试模式
    $(".tiaoshi").click(function () {
        changeMode(2);
    });
    //自动模式
    $(".zidong").click(function () {
        changeMode(1);
    });
    //手动模式
    $(".shoudong").click(function () {
        changeMode(0);
    });
    //计算重量
    $('#freespeed').change(function () {
        calcWeight();
    });
    $('#freesecs').blur(function () {
        calcWeight();
    });
    //触发投喂
    $("#chufatouwei").click(function () {
        Request.builder()
            .url(STATION_DETAIL + "/" + stationId)
            .isToken(true)
            .callback(function (e) {
                if (e.code === "00000") {
                    if (e.data.type) {
                        var lock = false;
                        var confirm = LayerUtil.confirm("当前设备为校准设备，是否切换为常规机器?", function () {
                            if (!lock) {
                                lock = true;
                                Request.builder()
                                    .url(STATION_SET_JZ + "/" + stationId + "/" + 0)
                                    .isToken(true)
                                    .callback(function (e) {
                                        if (e.code === "00000") {
                                            LayerUtil.successMsg(ERROR_MSG.SUCCESS)
                                            setTimeout(function () {
                                                chufatouwei()
                                            }, 1000)
                                        } else {
                                            LayerUtil.failMsg(e.msg != null ? e.msg : ERROR_MSG.FAIL)
                                        }
                                    }).post();
                                layer.close(confirm);
                            }
                        }, null)
                    } else {
                        chufatouwei()
                    }
                }
            }).get();
    })
});

function chufatouwei() {
    Validator.builder()
        .dom($("#replenishForm"))
        .customValidate(checkReplenishForm)
        .customSubmit(function (e) {
            if (!e) {
                return false;
            }
            var lock = false;
            var confirm = LayerUtil.confirm("确认执行补投?", function () {
                if (!lock) {
                    lock = true;
                    var data = {};
                    var mode = $("#freespeed").val();
                    var freesecs = $.trim($("#freesecs").val());
                    if (freesecs === "0") {
                        LayerUtil.failMsg("指定时长不能为0")
                        layer.close(confirm);
                        return false;
                    }
                    data.mode = mode;
                    data.secs = freesecs;
                    Request.builder()
                        .url(STATION_FEED + "/" + stationId)
                        .data(data)
                        .isToken(true)
                        .callback(function (e) {
                            if (e.code === "00000") {
                                LayerUtil.successMsg("指令已发出,请刷新页面查看结果~")
                            } else {
                                LayerUtil.failMsg(e.msg != null ? e.msg : ERROR_MSG.FAIL)
                            }
                        }).post();
                    layer.close(confirm);
                }
            }, null)
        }, null).do();
}

function updateTempType(tempType) {
    Request.builder()
        .url(STATION_UPDATE_TYPE + "/" + stationId)
        .data({"tempType": tempType})
        .isToken(true)
        .callback(function (e) {
            if (e.code === "00000") {
                LayerUtil.successMsg(ERROR_MSG.SUCCESS)
            } else {
                LayerUtil.failMsg(e.msg != null ? e.msg : ERROR_MSG.FAIL)
            }
        }).post();
}

//设置设备信息
function setStationInfo(data) {
    Form.setHtml($("#baseinfo"), data)
    $("#statoninfo").html("设备信息");
    $("#workshopName").html(data.companyName + " " + data.workshopName);
    if (data.status === 0) {
        $("#status").html('<i class="fa fa-circle text-info pr-1"></i>在线');
    } else {
        $("#status").html('<i class="fa fa-circle text-muted pr-1"></i>离线');
    }
    var runStatesDom = $("#runStates");
    if (data.stopStatus === 0) {
        runStatesDom.html('运行');
        runStatesDom.addClass('label-primary')
    } else if (data.stopStatus === 1) {
        runStatesDom.html('停止');
        runStatesDom.addClass('label-danger')
    }
    var bait_warningDom = $("#bait_warning");
    if (data.baitStatus === 0) {
        bait_warningDom.html('有料');
        bait_warningDom.addClass('label-primary')
    } else if (data.baitStatus === 1) {
        bait_warningDom.html('无料');
        bait_warningDom.addClass('label-danger')
    }
    var airTemp = data.airTemp;
    var waterTemp = data.waterTemp;
    var tempType = data.tempType;
    if (waterTemp < 0 || waterTemp > 35) {
        waterTemp = -100;
    }
    if (airTemp < -10 || airTemp > 35) {
        airTemp = -100;
    }
    if (waterTemp === -100 && airTemp === -100) {
        $("#tempValueStyle").hide()
    } else {
        if (waterTemp === -100) {
            $("#waterTempValue").html("##");
        } else {
            $("#waterTempValue").html(waterTemp.toFixed(1));
        }
        if (airTemp === -100) {
            $("#airTempValue").html("##");
        } else {
            $("#airTempValue").html(airTemp.toFixed(1));
        }
        if (tempType === 0) {
            $("#yincang").show()
            $("#yincang1").hide()
            $("#airTemp").removeClass("tempChoose");
            $("#waterTemp").addClass("tempChoose");
        } else {
            $("#yincang").hide()
            $("#yincang1").show()
            $("#airTemp").addClass("tempChoose");
            $("#waterTemp").removeClass("tempChoose");
        }
    }
}

//文件导出
function export_excel() {
    //选择表格
    var table = $('.monthProducts');
    //判断表格是否存在且不为空表格
    if (table && table.length) {
        $(table).table2excel({
            exclude: ".hidden_input", // 不导出的class
            filename: "月生产日志", // 导出的文件名
            fileext: ".xls", // 文件类型
            exclude_img: true, // 是否导出图片
            exclude_links: false, // 是否导出超链接
            exclude_inputs: true, // 是否导出输入框中的内容
            preserveColors: false // 是否导出背景颜色
        });
    }
}

//设置养殖池信息
function setPoolInfo(data) {
    Form.setHtml($("#poolinfo"), data)
    $("#guge").html('<em>' + data.speciesNum + '</em> 条/ <em>' + (data.speciesSpec).toFixed(1) + '</em>g');
    $("#plan").html('<em>' + data.planWeight + '</em>g/<em>' + data.planNum + '</em>次');
    $("#feed").html('<em>' + data.feedWeight + '</em>g/<em>' + data.feedNum + '</em>次');
    if (data.poolWidth === 0) {
        $("#pool").html("πx" + data.poolLong + "²x" + data.poolHeight);
        $("#poolv").html(data.poolVolume + "m³");
    } else {
        $("#pool").html(data.poolLong + "x" + data.poolWidth + "x" + data.poolHeight);
        $("#poolv").html(data.poolVolume + "m³");
    }
}

//设置设备状态
function setStationStatus(data) {
    Form.setHtml($("#statusinfo"), data)
    $("#stationStatus").html("设备模式");
    setStationStatusMode(data.mode)
}

function setStationStatusMode(mode) {
    var modeInfoDom = $("#mode");
    var modeDom = $("#statusinfomode");
    if (mode === 2) {
        modeInfoDom.html('调试模式');
        modeInfoDom.addClass('label-debug')
        modeDom.html('调试模式');
        modeDom.addClass('label-debug')
        $("#tiaoshispan").html('<p class="m-b-none text-warning text-center m-r-5 blink2"><i class="fa fa-2x fa-caret-up"></i></p>');

    } else if (mode === 1) {
        modeInfoDom.html('自动模式');
        modeInfoDom.addClass('label-primary')
        modeDom.html('自动模式');
        modeDom.addClass('label-primary')
        $("#zidongspan").html('<p class="m-b-none text-warning text-center m-r-5 blink2"><i class="fa fa-2x fa-caret-up"></i></p>');

    } else {
        modeInfoDom.html('手动模式');
        modeInfoDom.addClass('label-danger')
        modeDom.html('手动模式');
        modeDom.addClass('label-danger')
        $("#shoudongspan").html('<p class="m-b-none text-warning text-center m-r-5 blink2"><i class="fa fa-2x fa-caret-up"></i></p>');
    }
}

//设置投喂i任务
function setTask(data) {
    if (data.showType === 0) {
        var calibrationValue = "(";
        if (data.normalValue !== "") {
            calibrationValue += data.normalValue + ";";
        }
        if (data.highValue !== "") {
            calibrationValue += data.highValue + ";";
        }
        calibrationValue += ")";
        $("#baitName").html(data.baitCompanyName + "-" + data.baitBrandName + "-" + data.baitSizeName + "mm" + "—" + calibrationValue);
    } else {
        if (data.shortName === "") {
            $("#baitName").html(data.baitCompanyName + "-" + data.baitBrandName + "-" + data.baitSizeName + "mm");
        } else {
            $("#baitName").html(data.shortName);
        }
    }
    if (data.taskJson != null && data.taskJson !== "") {
        var taskJson = JSON.parse(data.taskJson);
        var orderArr = sortObjectArray(taskJson, ['hour', 'min'], "asc");
        var html = '';
        $("#taskTime").children().each(function () {
            $(this).removeClass("label-danger");
        })
        $.each(orderArr, function (index, item) {
            var week = item.week;
            if (week === null || week === undefined || week === "") {
                week = "1,2,3,4,5,6,7"
            }
            var htmlWeek = ``
            var arr = week.toString().split(",");
            if (arr.length !== 7) {
                if (arr.indexOf('1') != -1) {
                    htmlWeek += `周一`
                }
                if (arr.indexOf('2') != -1) {
                    htmlWeek += `周二`
                }
                if (arr.indexOf('3') != -1) {
                    htmlWeek += `周三`
                }
                if (arr.indexOf('4') != -1) {
                    htmlWeek += `周四`
                }
                if (arr.indexOf('5') != -1) {
                    htmlWeek += `周五`
                }
                if (arr.indexOf('6') != -1) {
                    htmlWeek += `周六`
                }
                if (arr.indexOf('7') != -1) {
                    htmlWeek += `周日`
                }
                htmlWeek = htmlWeek.replace(/(.{2})/g, "$1，"); // 在每两个字符后面添加逗号
                //去最后的点
                htmlWeek = htmlWeek.substring(0, htmlWeek.length - 1);
            } else {
                htmlWeek += "每天";
            }

            var hour = item.hour;
            var dom = $("#taskTime").find(".dnum" + hour);
            if (dom.length > 0 && !dom.hasClass("label-danger")) {
                dom.addClass("label-danger")
            }
            var speedmodeText = "";
            if (item.mode === 'normal') {
                speedmodeText = "低速模式";
            } else {
                speedmodeText = "高速模式";
            }
            var i = index * 1 + 1;
            html += '<tr>\n' +
                '     <td style="text-align: center; vertical-align: middle; ">任务#' + i + '</td>\n' +
                '     <td style="text-align: center; vertical-align: middle; ">' + htmlWeek + '</td>\n' +
                '     <td style="text-align: center; vertical-align: middle; ">' + item.hour + ':' + item.min + '</td>\n' +
                '     <td style="text-align: center; vertical-align: middle; ">' + speedmodeText + '</td>\n' +
                '     <td style="text-align: center; vertical-align: middle; ">' + item.weight + '</td>\n' +
                '</tr>'
        });
        $("#taskList").html(html);
    }


}

//投喂趋势图
function touwei(month) {
    var trend_default_option = {
        tooltip: {
            trigger: 'axis',
            formatter: function (params) {
                var html = '';
                html += "<div style='margin-bottom:5px;padding:0 12px;width:100%;height:24px;line-height:24px;background:pink;border-radius:3px;'>"
                html += "<p>日期：" + params[1].name + "</p>";
                html += "</div>"

                for (var i = 1; i < params.length; i++) {
                    html += '<div style="color: #000;font-size: 14px; padding:0 6px;line-height: 24px">';
                    html += '<span style="display:inline-block;margin-right:5px;border-radius:2px;width:10px;height:10px;background-color:' + params[i].color + ';"></span>';
                    html += params[i].seriesName + ' <span class="number m-l-md pull-right">' + params[i].data + 'g</span>';
                    html += '</div>';
                }

                return html;
            }
        },
        grid: {left: '53', top: '30', right: '7', bottom: '40'},
        xAxis: {
            type: 'category',
            data: [],
            axisTick: {alignWithLabel: true},
            axisLine: {show: true},
            axisLabel: {margin: 25}
        },
        yAxis: [{
            type: 'value',
            name: ' ',
            min: 0,
            axisLabel: {formatter: '{value} '},
            nameTextStyle: {align: "right"},
        }, {
            type: 'value',
            name: '',
            min: 0,
            axisLabel: {formatter: '{value} '}
        }],
        series: [
            {
                type: 'bar',
                itemStyle: {
                    color: function (params) {
                        return 'rgba(0,0,0,0.05)';
                    }
                },
                emphasis: {
                    itemStyle: {
                        color: 'rgba(0,0,0,0.15)'
                    }
                },
                barGap: '-100%',
                barCategoryGap: '40%',
                data: [],
                animation: false
            },
            {

                name: '执行投喂',
                lineStyle: {width: 2},
                itemStyle: {normal: {color: '#73BFA9'}},
                type: 'bar',
                stack: 'f',
                smooth: true,
                data: []
            },
            {
                name: '补充投喂',
                lineStyle: {width: 2},
                itemStyle: {normal: {color: '#4996CF'}},
                type: 'bar',
                stack: 'f',
                smooth: true,
                data: []
            },
            {
                name: '实际投喂',
                lineStyle: {width: 2},
                itemStyle: {normal: {color: '#af64bb'}},
                type: 'line',
                smooth: true,
                data: []
            },
        ]
    };
    var xaxis = [];
    var shadow = [];
    var sdata0 = [];
    var sdata1 = [];
    var sdata2 = [];
    var max = 0;
    Request.builder()
        .url(STAION_PRODUCE_RECORD_MONTH_FEED + "?stationId=" + stationId)
        .data({"month": month})
        .isToken(true)
        .callback(function (e) {
            var data = e.data;
            data.forEach(function (item) {
                xaxis.push(item.time);
                shadow.push(0);
                sdata0.push(item.feedWeight);
                sdata1.push(item.feedWeight - item.replenishWeight);
                sdata2.push(item.replenishWeight);
                max = item.feedWeight > max ? item.feedWeight : max;
            });
            max = max ? parseInt(Math.ceil(max / 100)) * 150 : 100
            shadow.fill(max);
            var trend_option = $.extend({}, trend_default_option);
            trend_option.xAxis.data = xaxis;
            trend_option.series[0].data = shadow;
            trend_option.series[1].data = sdata1;
            trend_option.series[2].data = sdata2;
            trend_option.series[3].data = sdata0;
            trend_option.yAxis[0].max = max;
            trend_option.yAxis[1].max = max;
            trend_option.yAxis[0].interval = parseInt(Math.ceil(max / 100)) * 20 > 0 ? parseInt(Math.ceil(max / 100)) * 20 : 20;
            trend_option.yAxis[1].interval = parseInt(Math.ceil(max / 100)) * 20 > 0 ? parseInt(Math.ceil(max / 100)) * 20 : 20;
            var chart = echarts.init(document.getElementById('feed_chart'));
            chart.setOption(trend_option);
            chart.on('click', function (params) {
                $("#feedDayTime").val(params.name);
                $("#feedTime").html(params.name);
                $(".feedDay").bootstrapTable('refresh', {pageNumber: 1});//刷新Table，Bootstrap Table 会自动执行重新查询
            });
            setInterval(() => {
                chart.resize();
            }, 100)
        }).get();
}

//详情
function detail() {
    var index = LayerUtil.loading();
    Request.builder()
        .url(STATION_DETAIL + "/" + stationId)
        .isToken(true)
        .callback(function (e) {
            if (e.code === "00000") {
                var data = e.data;
                setStationInfo(data);
                setPoolInfo(data);
                setStationStatus(data);
                setTask(data);
                $("#freesecs").attr("nsecs", data.normalSecs);
                $("#freesecs").attr("hsecs", data.highSecs);
                layer.close(index);
            } else if (e.code === "C0013") {
                LayerUtil.failMsg(e.msg != null ? e.msg : ERROR_MSG.FAIL)
                setTimeout(function () {
                    window.location.href = "/admin/station/index.html";
                }, 1000)
            }
        }).get();
}


//切换模式
function changeMode(mode) {
    var lock = false;
    var confirm = LayerUtil.confirm("确认变更模式?", function () {
        if (!lock) {
            lock = true;
            Request.builder()
                .url(STATION_CHANGE_MODE + "/" + stationId)
                .data({"mode": mode})
                .isToken(true)
                .callback(function (e) {
                    if (e.code === "00000") {
                        LayerUtil.successMsg("指令已发出,请刷新页面查看结果~")
                    } else {
                        LayerUtil.failMsg(e.msg != null ? e.msg : ERROR_MSG.FAIL)
                    }
                    layer.close(confirm);
                    $(".mx_validator_button").attr("disabled", false)
                }).post();
        }
    }, null)
}

//池子样式计算
function changePond(value) {
    if (value == 'squaresPond') {
        squaresPondShow.style.display = "block";
        circlesPondShow.style.display = "none";
        anisePondShow.style.display = "none";
        pondStatus = 0
    } else if (value == 'circlesPond') {
        squaresPondShow.style.display = "none";
        circlesPondShow.style.display = "block";
        anisePondShow.style.display = "none";
        pondStatus = 1
    } else if (value == 'anisePond') {
        squaresPondShow.style.display = "none";
        circlesPondShow.style.display = "none";
        anisePondShow.style.display = "block";
        pondStatus = 2
    }
}

//计算重量
function calcWeight() {
    var freesecs = $("#freesecs").val();//获取秒数
    var mode = $("#freespeed").val();//获取模式
    var secs100 = 0;
    //获取每个模式对应的投100g需要秒数(数据库存值时为精准，secs100的值扩大100倍)
    if (mode === 'normal') {
        secs100 = $("#freesecs").attr("nsecs");
    } else if (mode === 'high') {
        secs100 = $("#freesecs").attr("hsecs");
    }
    var freeweight = 0;
    if (secs100 > 0) {
        var secs1 = secs100 / 10000;//1g多少秒(数据库存值时为精准，secs100的值扩大100倍)，综上除以10000
        freeweight = (freesecs / secs1).toFixed(2)//计算对应秒数的对应重量
    }
    $("#freeweight").val(freeweight)//将值输入给input
}

function showPopupShowDiv() {
    var innerHTML = $.trim(event.srcElement.innerHTML);
    if (innerHTML.length > 8) {
        var div = event.srcElement;
        var showDiv = div.parentElement.childNodes;
        showDiv[1].nextSibling.style.display = "block";
    }
    if (event && event.srcElement && event.srcElement.className == "popupDiv") {
        var div = event.srcElement;
        var showDiv = div.parentElement.childNodes;
        showDiv[1].nextSibling.style.visibility = "visible";
    }
}

function clearPopupShowDiv() {
    if (event && event.srcElement && event.srcElement.className == "popupDiv") {
        var div = event.srcElement;
        var showDiv = div.parentElement.childNodes;
        showDiv[1].nextSibling.style.visibility = "hidden";
    }
}

feedDay = [
    {
        field: 'seq',
        title: '序号',
        align: 'center',
        valign: 'middle'
    }, {
        field: 'startTime',
        title: '开始',
        align: 'center',
        valign: 'middle'
    }, {
        field: 'endTime',
        title: '结束',
        align: 'center',
        valign: 'middle'
    }, {
        field: 'weight',
        title: '投喂量(g)',
        align: 'center',
        valign: 'middle'
    }, {
        field: 'type',
        title: '投喂类型',
        align: 'center',
        valign: 'middle',
        width: 100,
        formatter: function (value, row, index) {
            if (value === "planfeed") {
                return "<span style='background-color:#1ab394;color: #ffffff;padding: 4px 5px;border-radius: 0.25rem;'>执行投喂</span>"
            } else if (value === "ext1feed") {
                return "<span style='background-color:#663399;color: #ffffff;padding: 4px 5px;border-radius: 0.25rem;'>定量补投</span>"
            } else if (value === "ext2feed") {
                return "<span style='background-color:#ED5565;color: #ffffff;padding: 4px 5px;border-radius: 0.25rem;'>定时补投</span>"
            } else {
                return "未知";
            }
        }
    }, {
        field: 'status',
        title: '状态',
        align: 'center',
        valign: 'middle',
        formatter: function (value, row, index) {
            if (value === 0) {
                return "<span style='color:green'>完成</span>"
            } else if (value === 1) {
                return "<span style='color:red'>中断</span>"
            } else {
                return "未知";
            }
        }
    }, {
        field: 'airTemp',
        title: '温度(℃)',
        align: 'center',
        valign: 'middle',
        formatter: function (value, row, index) {
            if (value < 0 || value > 35) {
                value = -100;
            }
            if (value === -100) {
                if (row.waterTemp < 0 || row.waterTemp > 35) {
                    row.waterTemp = -100;
                }
                if (row.waterTemp === -100) {
                    return "<span style='color:red'>##</span>"
                } else {
                    return "<span style='color:green'>" + (row.waterTemp).toFixed(1) + "</span>"
                }
            } else {
                return "<span style='color:green'>" + value.toFixed(1) + "</span>"
            }
        }
    }, {
        field: 'speed',
        title: '详情',
        align: 'center',
        valign: 'middle',
        formatter: function (value, row, index) {
            return PriceUtil.addPriceZero(PriceUtil.getPrice(row.speed, 100)) + "r/min," + (row.secs / 60).toFixed(1) + "min";
        }
    }
]
monthProducts = [
    {
        field: 'time',
        title: '日期',
        align: 'center',
        valign: 'middle'
    }, {
        field: 'speciesName',
        title: '养殖物种',
        align: 'center',
        valign: 'middle'
    }, {
        field: 'speciesSpec',
        title: '物种规格(g/条)',
        align: 'center',
        valign: 'middle',
        formatter: function (value, row, index) {
            return '<span style="font-weight: bold">' + value.toFixed(1) + '</span>'
        }
    }, {
        field: 'speciesNum',
        title: '物种数量',
        align: 'center',
        valign: 'middle',
        formatter: function (value, row, index) {
            return '<span style="font-weight: bold">' + value + '</span>'
        }
    }, {
        field: 'planWeight',
        title: '计划投喂(g)',
        align: 'center',
        valign: 'middle',
        formatter: function (value, row, index) {
            return '<span style="font-weight: bold">' + value + '</span>'
        }
    }, {
        field: 'planNum',
        title: '计划次数(次)',
        align: 'center',
        valign: 'middle',
        formatter: function (value, row, index) {
            return '<span style="font-weight: bold">' + value + '</span>'
        }
    }, {
        field: 'planWeight',
        title: '执行投喂(g)',
        align: 'center',
        valign: 'middle',
        formatter: function (value, row, index) {
            return '<span style="font-weight: bold;color: #73bfa9;">' + (row.feedWeight - row.replenishWeight) + '</span>'
        }
    }, {
        field: 'planNum',
        title: '执行次数(次)',
        align: 'center',
        valign: 'middle',
        formatter: function (value, row, index) {
            return '<span style="font-weight: bold">' + (row.feedNum - row.replenishNum) + '</span>'
        }
    }, {
        field: 'replenishWeight',
        title: '补充投喂(g)',
        align: 'center',
        valign: 'middle',
        formatter: function (value, row, index) {
            return '<span style="font-weight: bold;color: #4996cf;">' + value + '</span>'
        }
    }, {
        field: 'replenishNum',
        title: '补充次数(次)',
        align: 'center',
        valign: 'middle',
        formatter: function (value, row, index) {
            return '<span style="font-weight: bold">' + value + '</span>'
        }
    }, {
        field: 'feedWeight',
        title: '实际投喂(g)',
        align: 'center',
        valign: 'middle',
        formatter: function (value, row, index) {
            return '<span style="font-weight: bold;color: #af64bb;">' + value + '</span>'
        }
    }, {
        field: 'feedNum',
        title: '实际次数(次)',
        align: 'center',
        valign: 'middle',
        formatter: function (value, row, index) {
            return '<span style="font-weight: bold">' + value + '</span>'
        }
    }, {
        field: 'remark',
        title: '备注',
        align: 'center',
        valign: 'middle'
    }
]

contr = [
    {
        field: 'createTime',
        title: '控制时间',
        align: 'center',
        valign: 'middle',
        formatter: function (value, row, index) {
            return DateUtil.changeDateToString(value, DateFormatEnum.YYYY_MM_DD_HH_MM);
        }
    }, {
        field: 'createUser',
        title: '操作用户',
        align: 'center',
        valign: 'middle'
    }, {
        field: 'type',
        title: '控制类型',
        align: 'center',
        valign: 'middle',
        formatter: function (value, row, index) {
            if (value === 0) {
                return "<span style='color:#1c84c6;font-weight: bold;'>页面控制</span>";
            } else if (value === 1) {
                return "<span style='color:#73CDAA;font-weight: bold;'>设备控制</span>";
            }
        }
    }, {
        field: 'operate',
        title: '操作类型',
        align: 'center',
        valign: 'middle',
        formatter: function (value, row, index) {
            if (value === "feed") {
                return "<span>自由投喂</span>";
            } else if (value === "calibration") {
                return "<span>校准标定</span>";
            } else if (value === "task") {
                return "<span>设置任务</span>";
            } else if (value === "mode") {
                return "<span>切换模式</span>";
            } else if (value === "firmware") {
                return "<span>固件更新</span>";
            } else if (value === "reset") {
                return "<span>设备重启</span>";
            } else if (value === "status") {
                return "<span>读取状态</span>";
            } else if (value === "recon") {
                return "<span>对账召回</span>";
            } else if (value === "ration") {
                return "<span>定量补料</span>";
            } else if (value === "timing") {
                return "<span>持续补料</span>";
            } else if (value === "stop") {
                return "<span>停止上行</span>";
            } else if (value === "upgradeStart") {
                return "<span>固件更新</span>";
            }
        }
    }, {
        field: 'status',
        title: '状态',
        align: 'center',
        valign: 'middle',
        formatter: function (value, row, index) {
            if (value === 0) {
                return "<span style='color:red'>云端缓存</span>";
            } else if (value === 1) {
                return "<span style='color:green'>已下发</span>";
            } else if (value === 2) {
                return "<span style='color:green'>已应答</span>";
            } else if (value === 99) {
                return "<span style='color:red'>超时</span>";
            } else {
                return "未知";
            }
        }
    }, {
        field: 'content',
        title: '控制内容',
        align: 'center',
        valign: 'middle'
    }
]

function option(value, row, index) {
    return TableMultiple.tableOptionDefault(value, row, index);
}
